home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-21 | 3.4 KB | 161 lines | [TEXT/SPM ] |
- #define OLDROUTINELOCATIONS 0
- #include <ConditionalMacros.h>
- #include <Types.h> // For Str255
- #include <Dialogs.h> // For Alert
- #include <TextUtils.h> // For c2pstr
- #include <PLStringFuncs.h> // For PLstrcpy
- #include <ToolUtils.h> // For BitTst
- #include <Files.h>
-
- #include <console.h>
-
- #include <assert.h>
- #include <stdlib.h>
- #include <iostream.h>
-
- #include "macString.h"
-
- #define rUserAlert 129
-
- typedef multimap<macString,macString, less<macString> > mmap;
- mmap m;
-
- static void CatalogADirectory(long);
- static void DirID2FullPath(long, macString&);
- static Boolean NextFileInDirectory(long, HFileInfo&, macString&);
-
- long countFiles = 0;
- long countDirectories = 0;
-
- int main()
- {
- console_options.ncols = 135; // Works for 17" monitor.
- console_options.nrows = 50; // Works for 17" monitor.
- cecho2file("Dupes.log", 0, stdout);
-
- cout << "Dupes: Examining the default volume..." << endl;
- cout << endl;
-
- CatalogADirectory(fsRtDirID); // start at the root
- cout << endl;
-
- cout << "Total Directories = " << countDirectories << endl;
- cout << "Total Files = " << countFiles << endl;
- cout << endl;
-
- // At this point all the files are in mmap, indexed by the file name
- // Print out in sorted order
- mmap::iterator i;
- i = m.begin();
- while (i != m.end ())
- {
- cout << (*i).first << " -> " << (*i).second << endl;
- i++;
- }
- cout << endl;
-
- // Remove all the entries that have unique keys
- mmap::iterator j;
- i = m.begin();
- while (i != m.end ())
- {
- const macString& key = (*i).first;
- if (m.count(key) == 1)
- {
- j = i;
- j++;
- // cout << "Erasing "<< (*i).first << " -> " << (*i).second << endl;
- m.erase(i);
- }
- else
- {
- for (int ii = m.count(key); ii > 0; ii--)
- {
- // cout << "Saving "<< (*i).first << " -> " << (*i).second << endl;
- i++, j++;
- }
- }
- i = j;
- }
- cout << endl;
-
- // print out the list of files with duplicate names
- i = m.begin();
- while (i != m.end ())
- {
- cout << (*i).first << " -> " << (*i).second << endl;
- i++;
- }
- cout << endl;
-
- return EXIT_SUCCESS;
- }
-
- static void CatalogADirectory(
- long iDir)
- {
- HFileInfo fileInfo;
- macString sName;
- macString sDir;
- macString sFull;
-
- DirID2FullPath(iDir, sDir);
- cout << sDir << endl;
-
- fileInfo.ioFDirIndex = 0;
- fileInfo.ioVRefNum = 0;
- while (NextFileInDirectory(iDir, fileInfo, sName)){
- if (fileInfo.ioFlAttrib & ioDirMask)
- { // another directory, recurse
- countDirectories++;
- CatalogADirectory(fileInfo.ioDirID);
- }
- else
- { // file, add to catalog
- countFiles++;
- sFull = sDir + sName;
- // cout << sDir << sName << endl;
- cout << sFull << endl;
- m.insert (pair<const macString, macString> (sName, sFull));
- }
- }
- }
-
- static void DirID2FullPath(
- long dirID,
- macString& sFullPath)
- {
- DirInfo dirInfo;
- Str255 str255Dir;
- OSErr err;
- macString sTemp;
-
- sFullPath = "";
- dirInfo.ioDrParID = dirID;
- dirInfo.ioNamePtr = str255Dir;
- do {
- dirInfo.ioVRefNum = 0;
- dirInfo.ioFDirIndex = -1;
- dirInfo.ioDrDirID = dirInfo.ioDrParID;
- err = PBGetCatInfo((CInfoPBRec *)&dirInfo, false);
- if (err)
- Debugger();
- sTemp = sFullPath;
- sFullPath = str255Dir;
- sFullPath += ":";
- sFullPath += sTemp;
- } while (dirInfo.ioDrDirID != fsRtDirID); // The root, e.g. "pb:"
- }
-
- static Boolean NextFileInDirectory(
- long iDir,
- HFileInfo& fileInfo,
- macString& s)
- {
- fileInfo.ioFDirIndex++;
- fileInfo.ioDirID = iDir;
- fileInfo.ioNamePtr = (unsigned char *)s;
- return PBGetCatInfo((CInfoPBRec *)&fileInfo, false) == noErr;
- }
-
-